<template>
  <div class="task-todo-page">
    <el-card class="todo-card">
      <template #header>
        <div class="card-header">
          <span>待办任务</span>
          <el-button type="primary" @click="handleAdd" v-if="hasPerm('task:todo:add')">新增任务</el-button>
        </div>
      </template>
      
      <el-table :data="todoList" style="width: 100%">
        <el-table-column prop="taskCode" label="任务编号" width="120" />
        <el-table-column prop="taskName" label="任务名称" width="200" />
        <el-table-column prop="assignee" label="负责人" width="100" />
        <el-table-column prop="priority" label="优先级" width="100">
          <template #default="scope">
            <el-tag :type="getPriorityType(scope.row.priority)">
              {{ getPriorityText(scope.row.priority) }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="deadline" label="截止日期" width="120" />
        <el-table-column prop="status" label="状态" width="100">
          <template #default="scope">
            <el-tag type="warning">待处理</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="200">
          <template #default="scope">
            <el-button size="small" @click="handleView(scope.row)" v-if="hasPerm('task:todo:view')">查看</el-button>
            <el-button size="small" type="primary" @click="handleEdit(scope.row)" v-if="hasPerm('task:todo:edit')">编辑</el-button>
            <el-button size="small" type="success" @click="handleComplete(scope.row)" v-if="hasPerm('task:todo:complete')">完成</el-button>
            <el-button size="small" type="danger" @click="handleDelete(scope.row)" v-if="hasPerm('task:todo:delete')">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { hasPerm } from '@/utils/permission'
import { ElMessage } from 'element-plus'

const todoList = ref([])

const getPriorityType = (priority) => {
  const priorityMap = {
    'high': 'danger',
    'medium': 'warning',
    'low': 'info'
  }
  return priorityMap[priority] || 'info'
}

const getPriorityText = (priority) => {
  const priorityMap = {
    'high': '高',
    'medium': '中',
    'low': '低'
  }
  return priorityMap[priority] || '未知'
}

const handleAdd = () => {
  ElMessage.info('新增待办任务功能')
}

const handleView = (row) => {
  ElMessage.info(`查看任务：${row.taskCode}`)
}

const handleEdit = (row) => {
  ElMessage.info(`编辑任务：${row.taskCode}`)
}

const handleComplete = (row) => {
  ElMessage.info(`完成任务：${row.taskCode}`)
}

const handleDelete = (row) => {
  ElMessage.info(`删除任务：${row.taskCode}`)
}

onMounted(() => {
  // 模拟数据
  todoList.value = [
    {
      taskCode: 'TASK001',
      taskName: '客户需求分析',
      assignee: '张三',
      priority: 'high',
      deadline: '2025-08-05',
      status: 'pending'
    },
    {
      taskCode: 'TASK002',
      taskName: '产品设计评审',
      assignee: '李四',
      priority: 'medium',
      deadline: '2025-08-10',
      status: 'pending'
    },
    {
      taskCode: 'TASK003',
      taskName: '系统测试',
      assignee: '王五',
      priority: 'low',
      deadline: '2025-08-15',
      status: 'pending'
    }
  ]
})
</script>

<style scoped>
.task-todo-page {
  padding: 20px;
}

.todo-card {
  margin-bottom: 20px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
</style> 